

import * as PIXI from 'pixi.js';
import FadeOutText from 'gameApp/scenes/loading/fadeOutText';
import Rect from 'components/rect';
import CONST from 'common/const/loading';
const { Container } = PIXI;

export default class Transition {

  constructor({parent, onEnd}) {
    const data = [
      ['终于逃脱出来了'],
      ['使用了【DR PLANT水漾柔润防晒乳】,', '果然怎么晒都不怕了'],
      ['我要去植物医生门店签《"爱晒好女人"保证书》，', '向他们道谢～']
    ];

    this.parent = parent;
    this.container = new Container();

    const { list, ...other } = CONST.fadeOutText;

    const { view } = window.CFG;

    other.lineHeight = 50;

    let bg = new Rect({top: 0, left: 0, width: view.width, height: view.height, fill: 0x010101});
    this.container.addChild(bg);

    this._renderTextSense(data[0], other, () => {
      this._renderTextSense(data[1], other, () => {
        this._renderTextSense(data[2], other, () => {
          onEnd();
        });
      });
    });

  }

  _renderTextSense = (data, style, onEnd) => {
    const { lineTimeout = 0, ...other } = style;
    setTimeout(() => {

      if (this.fadeOutText && this.fadeOutText.container) this.container.removeChild(this.fadeOutText.container);

      this.fadeOutText = new FadeOutText({parent: this, list: data, ...other, onEnd});
      this.container.addChild(this.fadeOutText.container);

    }, lineTimeout);
  };
}
